/*
 *  listar_comentarios_request.cpp
 *  Wilson
 *
 *  Created by Sebastian Orfino on 1/5/12.
 *  Copyright 2012 lbs3. All rights reserved.
 *
 */

#include "VCPlugInHeaders.h"
//sdk include
#include "ILayoutUIUtils.h"
#include "IDocument.h"
#include "ErrorUtils.h"

//project include
#include "listar_comentarios_request.h"
#include "listar_comentarios_response.h"
#include "csxs_facade.h"
#include "xmp_facade.h"
#include "pugixml.hpp"

using namespace eventos;



void listar_comentarios_request::operator()(const csxs::event::Event * const eventParam)
{
	using namespace pugi;
	IDocument * frontDoc = Utils<ILayoutUIUtils>()->GetFrontDocument();
	if (!frontDoc) return;

	payload_ = eventParam->data;
	
	xml_document doc;
	xml_parse_result result = doc.load(eventParam->data);
	
	if (!result) {
		PMString msg(result.description());
		msg.SetTranslatable(kFalse);
		ErrorUtils::PMSetGlobalErrorCode((ErrorCode)result.status,&msg);
		return;
	}
	
	xmp::info_nota_t nota;
	nota.id = doc.child("payload").child("id").child_value();
	
	//todo: buscar notas dentro de frontDoc.
	xmp::wilson_metadata wilson_meta(::GetUIDRef(frontDoc)); 		
	listar_comentarios_response evt;
	evt.comentarios() = wilson_meta.listar_comentarios(nota);
	
	wilson::despachar(evt);
}
